home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / anXhelper.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  3KB  |  89 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. /*
  16.  * Helper process to simulate SIGIO signals from the X server to irsim's
  17.  * analyzer.  This problem is mostly due to ultrix's inability to generate
  18.  * SIGIO for anything other than tty's "Gumby says Ultrix is snake oil".  It
  19.  * isn't needed for bsd - 4.3.
  20.  *
  21.  * The strategy is to wait for input from the X server by doing a select on
  22.  * the server's file descriptor, which is set to be 0 by irsim, and sending
  23.  * a SIGIO signal to the parent process whenever there's input to be read.
  24.  * Handshaking is accomplished by waiting for a SIGINT signal from irsim.
  25.  * This handshaking is needed since we don't know when the parent process
  26.  * will decide to read the events and thus we avoid sending SIGIO signals
  27.  * until irsim reads all events from the queue.
  28.  */
  29.  
  30. #include <signal.h>
  31. #ifdef SYS_V
  32. #    ifndef hpux
  33. #        define signal( SIG, HAND )    sigset( SIG, HAND )
  34. #    endif
  35. #    include <termio.h>
  36. #else
  37. #    include <sys/ioctl.h>
  38. #endif
  39. #include <fcntl.h>
  40.  
  41.  
  42. /*
  43.  * SIGINT handler : Do nothing, just terminate pause
  44.  */
  45. int handler()
  46.   {
  47. #ifdef SYS_V
  48.     signal( SIGINT, handler );
  49. #endif
  50.     return( 0 );
  51.   }
  52.  
  53.  
  54. main()
  55.   {
  56.     int  parent;        /* parent process */
  57.     int  fdset;            /* fd-bit-set to check: fd == 0 always */
  58.     int  f;
  59.  
  60.     for( f = 1; f < 15; f++ )
  61.     (void) close( f );
  62.  
  63. #ifdef TIOCNOTTY
  64.     f = open( "/dev/tty", O_RDWR );    /* disconnect from terminal */
  65.     if( f > 0 )
  66.       {
  67.     ioctl( f, TIOCNOTTY, 0 );
  68.     (void) close( f );
  69.       }
  70. #endif
  71.  
  72.     parent = getppid();
  73.     signal( SIGINT, handler );
  74.     signal( SIGUSR1, SIG_IGN );
  75.  
  76.     do
  77.       {
  78.     fdset = 1;
  79.     if( select( 1, &fdset, 0, 0, 0 ) != 1 )
  80.         continue;
  81.     if( kill( parent, SIGIO ) != 0 )        /* parent died */
  82.         break;
  83.     (void) sigpause( 0 );
  84.       }
  85.     while( 1 );
  86.  
  87.     exit( 0 );
  88.   }
  89.